package com.example.com.skills_utf8;

import com.utils.Utils1;

import android.app.Activity;
import android.os.Bundle;
import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.TranslateAnimation;
import android.widget.ViewFlipper;

public class ChangeView24 extends Activity implements OnTouchListener{

	
	ViewFlipper viewFlipper;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_change_view24);

		viewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper);
		viewFlipper.setOnTouchListener(this);
		
		
	}
	
	
	float touchDownX, touchUpX;
	
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		
		int[] size =Utils1.getScreenSize(ChangeView24.this);
		
		
		 if (event.getAction() == MotionEvent.ACTION_DOWN) { 
	            // 取得左右滑动时手指按下的X坐标 
	            touchDownX = event.getX(); 
	            return true; 
	        } else if (event.getAction() == MotionEvent.ACTION_UP) { 
	            // 取得左右滑动时手指松开的X坐标 
	            touchUpX = event.getX(); 
	            // 从左往右，看前一个View 
	            if (touchUpX - touchDownX > 100) { 
	                // 设置View切换的动画 
	            /* 
	            	viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, 
	                        android.R.anim.slide_in_left)); 
	                viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, 
	                        android.R.anim.slide_out_right));
	                        */ 
	            	
	            	///*
	                // 显示下一个View 
	            	View view0 =viewFlipper.findViewById(R.id.layout_inside1);
	            	View view1 =viewFlipper.findViewById(R.id.tv_delete);
	            	//view0.scrollTo(0, 0);
	            	//view1.scrollTo(size[0], 0); 
	            	view0.setVisibility(View.VISIBLE);
	            	view1.setVisibility(View.GONE);
	            	//*/
	            	
	           
	              
	                // 从右往左，看后一个View 
	            } else if (touchDownX - touchUpX > 100) { 
	                // 设置View切换的动画 
	                // 由于Android没有提供slide_out_left和slide_in_right，所以仿照slide_in_left和slide_out_right编写了slide_out_left和slide_in_right 
	                /*
	            	viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, 
	                        R.anim.slide_in_right)); 
	                viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, 
	                        R.anim.slide_out_left)); 
	                        
	                // 显示前一个View 
	              	viewFlipper.showNext();
	                */
	            	  
	            	
	            	View view0 =viewFlipper.findViewById(R.id.layout_inside1);
	            	View view1 =viewFlipper.findViewById(R.id.tv_delete);
	         //   	view0.scrollTo(size[0]-200, 0);
	         //   	view1.scrollTo(200, 0);
	            	view0.setVisibility(View.GONE);
	            	view1.setVisibility(View.VISIBLE);
	            	
	   
	            	
	            } 
	            return true; 
	        } 
		 
		return false;
		
		
	}
	
	
	
}
